<div class="container">

    <div class="page-header">
        <div class="row">
            <h1 class="span8"><?=ucfirst($post_type)?> : View All</h1>
            <span class="span4 clearfix">
                  <a class="nav-control new-page w-18" href="<?=base_url($link.'/view_new?post_type='.$post_type)?>">
                        Add <?=ucfirst($post_type)?>
                    </a>
            </span>
        </div>


    </div>

    <div class="row">

        <div class="span12">

                <table class="table table-striped table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>Status</th>
                            <th>Date</th>
                            <th class="th-action center">Action</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?  foreach($all_posts as $post): ?> 

                            <tr>

                                <td colspan="3"><strong><?=$post['post_title']?></strong></td>
                                <td class="center">
                                    <a href="<?=base_url()?><?=$link?>/view_edit?post_ID=<?=$post['ID']?>&post_type=<?=$post_type?>"><i class="icon-pencil"></i> Edit</a> |
                                    <a href="<?=base_url()?><?=$link?>/delete/<?=$post['ID']?>?post_type=<?=$post_type?>" class="delete_post"><i class="icon-trash"></i> Delete</a>
                                </td> 

                            </tr>    

                            <?

                                $first_child = $this->translate->trans_res_array($this->pages_model->view_all_children($post['ID']));

                                if(count($first_child)>0){

                                    $k=0;
                                    foreach($first_child as $fc):?>

                                    <tr <?if($k%2==0)echo 'class="tr-odd"';?>>
                                        <td><a href="<?=base_url()?><?=$link?>/view_edit?post_ID=<?=$fc['ID']?>&post_type=<?=$post_type?>" class="row-title" rel="tooltip" data-original-title="Edit <?=$fc['post_title']?>"> - <?=$fc['post_title']?></a></td>
                                        <td><?=$fc['post_status']?></td>
                                        <td><?=date('d.m.Y / H:i',$fc['date_time'])?>h</td>
                                        <td class="center">
                                            <a href="<?=base_url()?><?=$link?>/view_edit?post_ID=<?=$fc['ID']?>&post_type=<?=$post_type?>"><i class="icon-pencil"></i> Edit</a> |
                                            <a href="<?=base_url()?><?=$link?>/delete/<?=$fc['ID']?>?post_type=<?=$post_type?>" class="delete_post"><i class="icon-trash"></i> Delete</a>
                                        </td>
                                    </tr>

                                    <?
                                        
                                        $second_child = $this->translate->trans_res_array($this->pages_model->view_all_children($fc['ID']));
                                        
                                        if(count($second_child)>0){

                                            foreach($second_child as $sc):?>

                                            <tr>
                                                <td><a href="<?=base_url()?><?=$link?>/view_edit?post_ID=<?=$sc['ID']?>&post_type=<?=$post_type?>" class="row-title"> - - <?=$sc['post_title']?></a></td>
                                                <td><?=$sc['post_status']?></td>
                                                <td><?=date('d.m.Y / H:i',$sc['date_time'])?>h</td>
                                                <td class="center">
                                                    <a href="<?=base_url()?><?=$link?>/view_edit?post_ID=<?=$sc['ID']?>&post_type=<?=$post_type?>"><i class="icon-pencil"></i> Edit</a> |
                                                    <a href="<?=base_url()?><?=$link?>/delete/<?=$sc['ID']?>?post_type=<?=$post_type?>" class="delete_post"><i class="icon-trash"></i> Delete</a>
                                                </td>
                                            </tr> 

                                            <? endforeach; ?> 

                                        <?}?>

                                    <? 
                                        $k++;
                                        endforeach; ?> 

                                <?}?>                                    

                            <? endforeach; ?>

                    </tbody>
                </table>

        </div>

    </div>

</div> <!-- /container -->

<script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function() {

            jQuery('.delete_post').live('click',function(){

                    var conf = confirm("Delete <?=ucfirst($post_type)?>?")
                    if (!conf){
                        return false;
                    }

                    window.location.href = jQuery(this).attr('href');

                    return false;

            });
            
            //jQuery('.row-title').tooltip({placement:'bottom'});
            //jQuery('.row-title').tooltip();

    } );
</script>